package org.example;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.http.HttpHost;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;

/**
 * Hello world!
 *
 */
public class ES_Doc_Get_06 {
    public static void main( String[] args ) throws Exception {
        // 创建ES客户端
        RestHighLevelClient client = new RestHighLevelClient(RestClient.builder
                (new HttpHost("localhost", 9200, "http")));
        // 查询数据
        GetRequest request = new GetRequest();
        request.index("user").id("1001");
        GetResponse response = client.get(request, RequestOptions.DEFAULT);

        // 响应状态
        System.out.println(response.getSourceAsString());
        client.close();
    }
}
